package com.life.goal.application.assembler;

import com.life.goal.application.dto.request.InsertOralBatchRequest;
import com.life.goal.application.dto.request.InsertOralRequest;
import com.life.goal.application.dto.request.InsertWordRequest;
import com.life.goal.domain.entity.OralSentence;
import com.life.goal.domain.entity.WordBook;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 组织请求对象领域对类
 */
@Component
public class EnglishDataAssembler {

    public WordBook buildWordBook(InsertWordRequest request) {
        return WordBook.builder()
                .word(request.getWord())
                .mean(request.getMean())
                .build();
    }

    public OralSentence buildOralSentence(InsertOralRequest request) {
        return OralSentence.builder()
                .chinese(request.getChinese())
                .english(request.getEnglish())
                .build();
    }

    public List<WordBook> buildWordBookList(List<InsertWordRequest> list) {
        List<WordBook> wordBooks = new ArrayList<>();
        for (InsertWordRequest request : list) {
            WordBook wordBook = WordBook.builder()
                    .word(request.getWord())
                    .mean(request.getMean())
                    .build();
            wordBooks.add(wordBook);
        }
        return wordBooks;
    }

    public List<OralSentence> buildOralSentenceList(InsertOralBatchRequest request) {
        List<InsertOralRequest> list = request.getData();
        List<OralSentence> oralSentences = new ArrayList<>();
        for (InsertOralRequest oralRequest : list) {
            OralSentence oralSentence = OralSentence.builder()
                    .oralType(request.getOralType())
                    .oralTypeDesc(request.getOralTypeDesc())
                    .scene(request.getScene())
                    .topic(request.getTopic())
                    .chinese(oralRequest.getChinese())
                    .english(oralRequest.getEnglish())
                    .build();
            oralSentences.add(oralSentence);
        }
        return oralSentences;
    }
}
